<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="1100px" append-to-body>
        
        <div class="card card-search">
            <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="100px">
                <el-form-item label="订单" prop="name">
                    <el-input v-model.trim="queryParams.name" placeholder="请输入订单" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item>

                <el-form-item label=" ">
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                </el-form-item>
            </el-form>
        </div>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" :loading="download" :disabled="download" @click="handleExport">导出</el-button>
            </el-col>
        </el-row>
        <el-tabs v-model="activeTab" @tab-click="handleStatus" type="border-card">
            <el-tab-pane v-for="(item, index) in status" :key="index" :label="item.label" :name="item.value.toString()"> </el-tab-pane>
        </el-tabs>
        <el-table v-loading="loading" :data="tableData" border script>
            <el-table-column label="店铺" prop="shop_name" min-width=""></el-table-column>
            <el-table-column label="订单" prop="name" min-width=""></el-table-column>
            <el-table-column label="出单时间" prop="createtime" min-width=""></el-table-column>
            <el-table-column label="支付状态" prop="financial_status" min-width=""></el-table-column>
            <el-table-column label="发货状态" prop="fulfillment_status" min-width=""></el-table-column>
            <el-table-column label="原始销售额$" prop="total_price" min-width="100"></el-table-column>
            <el-table-column label="原始物流费$" prop="freight" min-width="100"></el-table-column>
            <el-table-column label="原始采购费$" prop="material" min-width="100"></el-table-column>
            <el-table-column label="发货件数" prop="skuquantity" min-width="100"></el-table-column>
            <el-table-column label="打包费$" prop="LogisticsMarkupFee" min-width="100"></el-table-column>
            <el-table-column label="争议成本$" prop="dispute" min-width="100"></el-table-column>
            <el-table-column label="物流匹配状态" prop="freight_status" min-width="100"></el-table-column>
            <el-table-column label="采购匹配状态" prop="material_status" min-width="100"></el-table-column>
            <el-table-column label="争议匹配状态" prop="disputeapi_status" min-width="100"></el-table-column>
            <el-table-column label="币种" prop="currency" min-width="100"></el-table-column>
            <el-table-column label="美金汇率" prop="dollar" min-width="100"></el-table-column>
            <el-table-column label="实际销售额$" prop="total_pricex" min-width="100"></el-table-column>
            <el-table-column label="实际物流费$" prop="freightx" min-width="100"></el-table-column>
            <el-table-column label="实际采购费$" prop="materialx" min-width="100"></el-table-column>
            <el-table-column label="备注" prop="remarks" min-width="100"></el-table-column>
            <el-table-column label="渠道" prop="source" min-width="100"></el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getDetail"></pagination>
    </el-dialog>
</template>

<script>
import { PersonalInfo } from '@/api/order'
import { exportMonthlyPersonalList } from '@/api/shop'
import { exportFile } from '@/utils/index'
export default {
    name: 'DetailDialog',
    props: {
        value: {
            type: Boolean,
            default: false,
            required: true,
        },
        params: {
            type: Object,
            default: () => {},
            status: "",
        },
    },
    data() {
        return {
            total: 0,
            pageInfo: {
                page: 1,
                limit: 10,
            },
            // 查询参数
            queryParams: {
                name: undefined,
            },
            loading: true,
            download: false,
            tableData: [],
            activeTab: '',
            status: [
                { label: '全部', value: '' },
                { label: '多人店铺', value: 'SmallShop' },
                { label: 'FB,TT渠道', value: 'fb' },
                { label: 'email,ggad,impact渠道', value: 'email' },
            ],
        }
    },
    computed: {
        title() {
            return `订单明细`
        },
        dialogVisible: {
            get() {
                return this.value
            },
            set(val) {
                this.$emit('input', val)
            },
        },
    },
    watch: {
        params: {
            handler(val) {
                if (val.id) {
                    this.getDetail()
                }
            },
            immediate: true,
            deep: true,
        },
    },
    mounted() {
        // this.getDetail()
    },
    handleQuery() {
        this.pageInfo.page = 1
        this.getDetail()
    },
    methods: {
        handleExport() {
            this.download = true
            const params = { id: this.params.id,status: this.params.status }
            exportMonthlyPersonalList(params)
                .then(res => {
                    exportFile(res, () => {
                        this.download = false
                    })
                })
                .catch(err => {
                    this.download = false
                })
        },
        getDetail() {
            this.loading = true
            const params = { id: this.params.id,status: this.params.status ,page:this.pageInfo.page}
            PersonalInfo(params)
                .then(res => {
                    this.tableData = res.data.list
                    this.total = res.data.total
                })
                .finally(() => {
                    this.loading = false
                })
        },
        handleStatus(tab) {
            this.params.status = tab.name
            // if(this.params.status == ""){
                // this.download = true
            // }else{
                this.download = false
            // }

            this.tableData = []
            this.getDetail()
        },
    },
}
</script>

<style>
.form-class.el-form .el-form-item {
    width: 100%;
    margin-right: 0;
}
.form-class.el-form .el-form-item .el-input {
    width: 400px;
}
</style>
